import type { AddressItem } from '@/types'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAddressStore = defineStore('address', () => {
  const selectedAddress = ref<AddressItem>()

  /**
   * 更换选中的收货地址
   * @param val 收货地址信息
   */
  const changeSelectedAddress = (val: AddressItem) => {
    selectedAddress.value = val
  }

  /**
   * 清空选中的收货地址
   */
  const clearSelectedAddress = () => {
    selectedAddress.value = undefined
  }

  return { selectedAddress, changeSelectedAddress, clearSelectedAddress }
})
